﻿//https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-ii/

class Solution {
public:
    int maxProfit(vector<int>& prices)
    {
        //双指针
        // int ret=0;
        // int n=prices.size();
        // for(int i=0;i<n;i++)
        // {
        //     int j=i;
        //     while(j+1<n&&prices[j+1]>prices[j]) j++;
        //     ret+=prices[j]-prices[i];
        //     i=j;
        // }

        // return ret;

        //拆分成一天一天
        int ret = 0;
        int n = prices.size();
        for (int i = 1; i < n; i++)
        {
            if (prices[i - 1] < prices[i])
                ret += prices[i] - prices[i - 1];
        }

        return ret;
    }
};